<template lang="html">
  <div class="setup-content" app="MemberSetup">
    <template>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>账号信息</span>
        </div>
        <div class="setup-content-form">
          <el-form status-icon  label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名 ：" prop="pass" v-if="userInfo">
              <span>{{userInfo.username}}</span>
            </el-form-item>
            <el-form-item label="头像 ： " prop="checkPass" class="setup-content-form-head">
                <uploadImg @getUploadImg="uploadSuccess"   /><div class="setup-content-form-head-tig">仅支持JPG、GIF、PNG、JPEG、BMP格式，文件小于4M</div>
            </el-form-item>
            <el-form-item prop="checkPass" class="setup-content-form-head" v-if="userInfo">
              <img class="setup-content-form-head-img" :src="URL.PIC+headImg" alt="" v-model="headImg">
            </el-form-item>
            <el-form-item label="昵称 ： " prop="nickname" v-if="userInfo">
              <el-input maxlength="25" v-model="userInfo.nickName" class="nickname"></el-input>
            </el-form-item>
            <el-form-item label="登录密码 ： " prop="nickname" v-if="userInfo">
              <span>  已设置    </span><el-button type="text"  @click.native="routeToPath('/forgetPassword?alter=1')">修改</el-button>
            </el-form-item>
            <el-form-item label="手机号码 ： " prop="nickname" v-if="userInfo">
              <span>  {{userInfo.encryptMobile}}    </span><el-button type="text" @click.native="routeToPath('/changeBindTel?phone='+userInfo.mobile)">修改</el-button>
            </el-form-item>
<!--            <el-form-item label="绑定微信 ： " prop="nickname">-->
<!--              <span> {{userInfo.openid}} </span><el-button type="text">修改</el-button>-->
<!--            </el-form-item>-->
            <el-form-item>
              <el-button type="primary" class="setup-content-submit" :loading="isSubmit" @click="onSubmit">提交</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
    </template>
  </div>
</template>

<script>
import UploadImg from "@/components/Upload/UploadImg";

import {saveUserAvatar,saveNickName} from '@/api/member';

export default {
  name:'MemberSetup',
  components: { UploadImg },
  data() {
    return {
      userInfo:this.getUserInfo(),
      headImg:this.getUserInfo() !=  undefined ? this.getUserInfo().avatar : '',
      isSubmit:false,
    }
  },
  created(){

  },
  methods: {
    uploadSuccess(val) {
      this.headImg = val.data
    },
    errorMsg(res){
      this.$message.error('保存失败'+res.msg);
    },
    onSubmit(){
      if(this.userInfo.nickName!='' && this.userInfo.nickName!=null){
        this.isSubmit = true;
        saveNickName({nickName:this.userInfo.nickName}).then(res=>{
            if(res.code === 200){
              saveUserAvatar({avatarUrl:this.headImg}).then(data=>{
                  if(data.code === 200) {
                    this.$message({
                      message: '保存成功',
                      type: 'success'
                    });
                  }else{
                    this.errorMsg(res);
                  }
                this.isSubmit = false;
              });
            }else{
              this.errorMsg(res);
            }
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>

  .setup-content{
    margin-left: 200px;
    margin-top: 20px;
    margin-bottom: 20px;
  }
  .clearfix{ font-size: 16px;}
  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 100%;
  }

  .avatar-uploader{
    float: left;
    .el-button--primary{
      background-color: #DDDDDD;
      border-color: #DDDDDD;
    }
  }

  .setup-content-submit{
    width:120px;
    height:40px;
    background:#255B8A;
    border-radius:4px;
    border-color: #255B8A;
  }

  .setup-content-form{
      padding: 20px 50px;
      color: #666666;
    .setup-content-form-head {
      .upload-demo {
        div:nth-child(1) {
          float: left;
        }
      }
    }
    .setup-content-form-head-img{
      width:100px;
      height: 100px;
    }

    .setup-content-form-head-tig{
      padding-left: 100px;
      color: #888888;
      font-size: 12px;
    }

    .el-form-item{
      padding-top: 8px;
      margin-bottom: 0px;
    }
  }

  .el-button--text{
    width:84px;
    height:13px;
    font-size:14px;
    font-family:PingFang-SC-Medium;
    font-weight:500;
    color:#255B8B;
  }

  .el-form-item__label{
    font-size: 14px;
    color: #666666;
    font-family:PingFang-SC-Medium;
    font-weight:500;
  }

  .nickname{
    width: 30%;
  }
</style>
